package ventanas;

import baseDeDatosJDBC.AdministradorDeConexiones;
import clases.TFnumericos;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public final class Altas extends javax.swing.JInternalFrame {

    public static boolean abierta = false;  
    
    //Constructor.    
    public Altas() {
        abierta = true;
        initComponents();
        condicionarTF();
        
        // Damos color a la ventana altas.
        getContentPane().setBackground(new java.awt.Color(205, 200, 177));
        
        //Definimos la dimension de la ventana altas.
        setPreferredSize(new java.awt.Dimension(738, 580));
        
        //Posicionamos la ventana altas en la esquina izquierda.
        setLocation(0, 0);

        cargarCmbs();
        
        try {
            agregarAnio();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "No se pudo leer archivo del año", "Advertencia", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
        }
        
        pack();
    }

    //Indicamos que los textfield reciban solo numeros y una cantidad limitada.
    public static void limitarYNumericosTextField(JTextField textField, int maximo) {
        textField.setDocument(new TFnumericos(textField, maximo));
    }
    
    //Condiciona los textfield a 4 digitos.
    public static void condicionarTF1(JPanel panel) {

        for (int i = 0; i < panel.getComponentCount(); i++) {
            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                limitarYNumericosTextField (textField,4);
            }
        }
    }

    //Condiciona todos los textfield a la cantidades indicadas.
    public void condicionarTF() {
        limitarYNumericosTextField(jTextField1, 3);
        limitarYNumericosTextField(jTextField2, 3);
        limitarYNumericosTextField(jTextField3, 3);
        limitarYNumericosTextField(jTextField4, 2);
        limitarYNumericosTextField(jTextField5, 2);
        limitarYNumericosTextField(jTextField28, 2);
        limitarYNumericosTextField(jTextField29, 4);
        condicionarTF1(jPanel2);
        condicionarTF1(jPanel4);
        condicionarTF1(jPanel3);
        condicionarTF1(jPanel5);
    }

    //Carga de combos en el inicio (constructor)
    private void cargarCmbs() {
        String departamento = "Select * from siesca.departamento";
        String establecimiento = "Select * from siesca.establecimiento";
        String servicio = "Select * from siesca.servicio";

        try {            
            Connection conn = AdministradorDeConexiones.obtenerConexion();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(departamento);
            while (rs.next()) {
                jComboBox1.addItem(rs.getString("descripcion"));
            }
            rs.close();

            ResultSet est = st.executeQuery(establecimiento);
            while (est.next()) {
                jComboBox2.addItem(est.getString("descripcion"));
            }
            est.close();

            ResultSet serv = st.executeQuery(servicio);
            while (serv.next()) {
                jComboBox3.addItem(serv.getString("descripcion"));
            }
            serv.close();

            st.close();
            conn.close();

        } catch (Exception er) {
            
            JOptionPane.showMessageDialog(this, "No hay conexión con la base de datos!", "Advertencia", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            this.dispose();
        }
    }     

    private void agregarAnio() throws IOException {

        try {
            FileReader lectorArchivo = new FileReader("anio.txt");
            BufferedReader br = new BufferedReader(lectorArchivo);
            jLabel29.setText(br.readLine());

            br.close();
            lectorArchivo.close();

        }      
        
        catch (FileNotFoundException ex) {
           JOptionPane.showMessageDialog(this, "No se pudo leer archivo del año", "Advertencia", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
        }        
    }
    
           
    //Habilita un panel.
    private void habilitarPanel(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            panel.getComponent(i).setEnabled(true);
        }
    }
    
    //Bloquea un panel
    private void bloquearControles1Modulo(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            panel.getComponent(i).setEnabled(false);
        }
    }

    //Inicializa los TF cuando se habilita el segundo modulo.
    public void activarPanel2Modulo(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                textField.setEnabled(true);
                if (textField.getText().equals("")) {
                    textField.setText("0");
                }
            } else {
                panel.getComponent(i).setEnabled(true);
            }
        }
    }
    
    //Habilitar el segundo modulo.
    private void habilitarSegundoModulo() {
        sinNovedadesBTN.setEnabled(true);
        activarPanel2Modulo(jPanel2);
        activarPanel2Modulo(jPanel3);
        activarPanel2Modulo(jPanel4);
        activarPanel2Modulo(jPanel5);
        activarPanel2Modulo(jPanel7);
        guardarBTN.setEnabled(false);
    }
    
    //Bloquea el segundo modulo.
    private void BloquearSegundoModulo() {
        bloquearControles1Modulo(jPanel2);
        bloquearControles1Modulo(jPanel3);
        bloquearControles1Modulo(jPanel4);
        bloquearControles1Modulo(jPanel5);
        bloquearControles1Modulo(jPanel7);
        salirBTN.setEnabled(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        limpiarBTN = new javax.swing.JButton();
        jTextField5 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jTextField24 = new javax.swing.JTextField();
        jTextField16 = new javax.swing.JTextField();
        jTextField15 = new javax.swing.JTextField();
        jTextField13 = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jTextField23 = new javax.swing.JTextField();
        jTextField14 = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        jTextField19 = new javax.swing.JTextField();
        jTextField18 = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        jTextField12 = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextField11 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jTextField21 = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jTextField20 = new javax.swing.JTextField();
        jLabel35 = new javax.swing.JLabel();
        jTextField22 = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jTextField17 = new javax.swing.JTextField();
        jLabel55 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel56 = new javax.swing.JLabel();
        jLabel57 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel47 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jLabel48 = new javax.swing.JLabel();
        jTextField25 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel49 = new javax.swing.JLabel();
        jLabel50 = new javax.swing.JLabel();
        jLabel53 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        guardarBTN = new javax.swing.JButton();
        jLabel45 = new javax.swing.JLabel();
        jTextField26 = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jTextField7 = new javax.swing.JTextField();
        jTextField27 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        salirBTN = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        sinNovedadesBTN = new javax.swing.JButton();
        jLabel25 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jTextField28 = new javax.swing.JTextField();
        jTextField29 = new javax.swing.JTextField();

        setBackground(new java.awt.Color(205, 200, 177));
        setClosable(true);
        setTitle("Formulario de altas");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jPanel1.setBackground(new java.awt.Color(205, 200, 177));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Campos clave", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setText("Cod. Servicio:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 100, -1, -1));

        jLabel4.setText("Orden:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 130, -1, -1));

        jTextField2.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField2MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextField2MousePressed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 70, 40, -1));

        jLabel5.setText("Mes:");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 160, -1, -1));

        jLabel2.setText("Cod. Establecimiento:");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, -1, -1));

        jTextField4.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField4MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextField4MousePressed(evt);
            }
        });
        jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField4FocusLost(evt);
            }
        });
        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField4KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 130, 27, -1));

        jTextField1.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 0, 0), java.awt.Color.white));
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField1KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 40, 40, -1));

        jTextField3.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField3MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextField3MousePressed(evt);
            }
        });
        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField3KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 40, -1));

        jLabel9.setText("Zona Sanitaria:");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 80, -1, -1));

        jLabel1.setText("Cod. Departamento:");
        jLabel1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jLabel1KeyReleased(evt);
            }
        });
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, -1, -1));

        limpiarBTN.setBackground(new java.awt.Color(205, 200, 177));
        limpiarBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/impiar.png"))); // NOI18N
        limpiarBTN.setText("   Limpiar");
        limpiarBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarBTNActionPerformed(evt);
            }
        });
        jPanel1.add(limpiarBTN, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 150, -1, -1));

        jTextField5.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField5MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTextField5MousePressed(evt);
            }
        });
        jTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField5KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 160, 27, -1));

        jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Departamento.." }));
        jComboBox1.setEnabled(false);
        jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 40, 220, -1));

        jComboBox2.setBackground(new java.awt.Color(205, 200, 177));
        jComboBox2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Establecimiento.." }));
        jComboBox2.setEnabled(false);
        jComboBox2.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jComboBox2InputMethodTextChanged(evt);
            }
        });
        jPanel1.add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 70, 390, -1));

        jComboBox3.setBackground(new java.awt.Color(205, 200, 177));
        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione.." }));
        jComboBox3.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox3ItemStateChanged(evt);
            }
        });
        jPanel1.add(jComboBox3, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 100, 390, -1));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel7.setForeground(new java.awt.Color(51, 0, 255));
        jLabel7.setText("0");
        jLabel7.setAlignmentX(0.5F);
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 100, 30, 20));

        jLabel28.setText("Año de ingreso:");
        jPanel1.add(jLabel28, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 30, 90, -1));

        jLabel29.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel29.setForeground(new java.awt.Color(0, 153, 0));
        jPanel1.add(jLabel29, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 50, 60, -1));

        jPanel2.setBackground(new java.awt.Color(205, 200, 177));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Consultas por edad y sexo", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTextField24.setText("0");
        jTextField24.setEnabled(false);
        jTextField24.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField24.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField24KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField24, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 90, 40, -1));

        jTextField16.setText("0");
        jTextField16.setEnabled(false);
        jTextField16.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField16.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField16KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField16, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 90, 40, -1));

        jTextField15.setText("0");
        jTextField15.setEnabled(false);
        jTextField15.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField15.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField15KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField15, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 90, 40, -1));

        jTextField13.setText("0");
        jTextField13.setEnabled(false);
        jTextField13.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField13.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField13KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField13, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 90, 40, -1));

        jLabel18.setText("Fem.");
        jPanel2.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(62, 69, -1, -1));

        jLabel19.setText("Mas.");
        jPanel2.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 70, -1, -1));

        jLabel33.setText("Fem.");
        jPanel2.add(jLabel33, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 70, -1, -1));

        jTextField23.setText("0");
        jTextField23.setEnabled(false);
        jTextField23.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField23.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField23KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField23, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 90, 40, -1));

        jTextField14.setText("0");
        jTextField14.setEnabled(false);
        jTextField14.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField14.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField14KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField14, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 90, 40, -1));

        jLabel32.setText("Mas.");
        jPanel2.add(jLabel32, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 70, -1, -1));

        jTextField19.setText("0");
        jTextField19.setEnabled(false);
        jTextField19.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField19.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField19KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField19, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 90, 40, -1));

        jTextField18.setText("0");
        jTextField18.setEnabled(false);
        jTextField18.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField18.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField18KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField18, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 90, 40, -1));

        jLabel21.setText("Mas.");
        jPanel2.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 70, -1, -1));

        jLabel41.setText("Fem.");
        jPanel2.add(jLabel41, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 70, -1, -1));

        jLabel40.setText("Fem.");
        jPanel2.add(jLabel40, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 70, -1, -1));

        jTextField12.setText("0");
        jTextField12.setEnabled(false);
        jTextField12.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField12.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField12KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField12, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 90, 40, -1));

        jLabel37.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel37.setText("10 a 14 años");
        jPanel2.add(jLabel37, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 50, -1, -1));

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel15.setText("Menor a 1");
        jPanel2.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, -1, -1));

        jTextField11.setText("0");
        jTextField11.setEnabled(false);
        jTextField11.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField11.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField11KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 40, -1));

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel16.setText("1 año");
        jPanel2.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 50, -1, -1));

        jLabel17.setText("Mas.");
        jPanel2.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, -1, -1));

        jLabel39.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel39.setText("Mayor a 50");
        jPanel2.add(jLabel39, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 50, -1, -1));

        jTextField21.setText("0");
        jTextField21.setEnabled(false);
        jTextField21.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField21.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField21KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField21, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 90, 40, -1));

        jLabel23.setText("Mas.");
        jPanel2.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 70, -1, -1));

        jLabel38.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel38.setText("15 a 49 años");
        jPanel2.add(jLabel38, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 50, -1, -1));

        jLabel20.setText("Mas.");
        jPanel2.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 70, -1, -1));

        jLabel36.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel36.setText("5 a 9 años");
        jPanel2.add(jLabel36, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 50, -1, -1));

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel22.setText("2 a 4 años");
        jPanel2.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 50, -1, -1));

        jLabel34.setText("Fem.");
        jPanel2.add(jLabel34, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 70, -1, -1));

        jTextField20.setText("0");
        jTextField20.setEnabled(false);
        jTextField20.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField20.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField20KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField20, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 90, 40, -1));

        jLabel35.setText("Fem.");
        jPanel2.add(jLabel35, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 70, -1, -1));

        jTextField22.setText("0");
        jTextField22.setEnabled(false);
        jTextField22.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField22.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField22KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField22, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 90, 40, -1));

        jLabel24.setText("Mas.");
        jPanel2.add(jLabel24, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 70, -1, -1));

        jLabel26.setText("Fem.");
        jPanel2.add(jLabel26, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 70, -1, -1));

        jTextField17.setText("0");
        jTextField17.setEnabled(false);
        jTextField17.setMaximumSize(new java.awt.Dimension(30, 20));
        jTextField17.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField17KeyReleased(evt);
            }
        });
        jPanel2.add(jTextField17, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 90, 40, -1));

        jLabel55.setText("Total:");
        jPanel2.add(jLabel55, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 130, -1, -1));

        jLabel14.setText("0");
        jPanel2.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 130, -1, -1));

        jLabel56.setText("Diferencia:");
        jPanel2.add(jLabel56, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 130, -1, -1));

        jLabel57.setText("+ - cons");
        jPanel2.add(jLabel57, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 130, -1, -1));

        jPanel3.setBackground(new java.awt.Color(205, 200, 177));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel47.setText("Consultas 1era vez:");
        jPanel3.add(jLabel47, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 14, -1, -1));

        jTextField10.setText("0");
        jTextField10.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField10.setEnabled(false);
        jTextField10.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField10KeyReleased(evt);
            }
        });
        jPanel3.add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 38, -1));

        jLabel48.setText("Consultas ulterior vez:");
        jPanel3.add(jLabel48, new org.netbeans.lib.awtextra.AbsoluteConstraints(197, 14, -1, -1));

        jTextField25.setText("0");
        jTextField25.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField25.setEnabled(false);
        jTextField25.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField25KeyReleased(evt);
            }
        });
        jPanel3.add(jTextField25, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 10, 38, -1));

        jLabel10.setText("0");
        jPanel3.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 10, -1, -1));

        jLabel49.setText("Diferencia:");
        jPanel3.add(jLabel49, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 10, -1, -1));

        jLabel50.setText("+ - cons");
        jPanel3.add(jLabel50, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 10, -1, -1));

        jLabel53.setText("Total:");
        jPanel3.add(jLabel53, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 10, -1, -1));

        jPanel4.setBackground(new java.awt.Color(205, 200, 177));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel11.setText("Consultas nuevas:");
        jPanel4.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 5, -1, -1));

        jTextField8.setText("0");
        jTextField8.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField8.setEnabled(false);
        jTextField8.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField8KeyReleased(evt);
            }
        });
        jPanel4.add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 2, 36, -1));

        jLabel12.setText("Consultas repetidas:");
        jPanel4.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(201, 5, -1, -1));

        jTextField9.setText("0");
        jTextField9.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField9.setEnabled(false);
        jTextField9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField9MouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTextField9MouseReleased(evt);
            }
        });
        jTextField9.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField9KeyReleased(evt);
            }
        });
        jPanel4.add(jTextField9, new org.netbeans.lib.awtextra.AbsoluteConstraints(318, 2, 37, -1));

        jLabel13.setText("Total:");
        jPanel4.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(385, 5, -1, -1));

        jLabel44.setText("0");
        jPanel4.add(jLabel44, new org.netbeans.lib.awtextra.AbsoluteConstraints(423, 5, -1, -1));

        jPanel5.setBackground(new java.awt.Color(205, 200, 177));
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        guardarBTN.setBackground(new java.awt.Color(205, 200, 177));
        guardarBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        guardarBTN.setText("   Guardar");
        guardarBTN.setEnabled(false);
        guardarBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarBTNActionPerformed(evt);
            }
        });
        guardarBTN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                guardarBTNKeyReleased(evt);
            }
        });
        jPanel5.add(guardarBTN, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 0, -1, -1));

        jLabel45.setText("Total control de embarazos:");
        jPanel5.add(jLabel45, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 15, -1, -1));

        jTextField26.setText("0");
        jTextField26.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField26.setEnabled(false);
        jTextField26.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField26MouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTextField26MouseReleased(evt);
            }
        });
        jTextField26.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField26KeyReleased(evt);
            }
        });
        jPanel5.add(jTextField26, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, 39, -1));

        jLabel6.setText("Horas de atención:");

        jLabel46.setText("Numero de hoja:");

        jButton2.setText("Sin novedades");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(100, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(74, 74, 74)
                .addComponent(jLabel46)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField27, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(55, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jLabel46)
                    .addComponent(jTextField27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(22, 22, 22))
        );

        jPanel5.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 52, -1, -1));

        salirBTN.setBackground(new java.awt.Color(205, 200, 177));
        salirBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/salir.png"))); // NOI18N
        salirBTN.setText("Salir");
        salirBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirBTNActionPerformed(evt);
            }
        });
        salirBTN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                salirBTNKeyReleased(evt);
            }
        });
        jPanel5.add(salirBTN, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 0, -1, -1));

        jPanel7.setBackground(new java.awt.Color(205, 200, 177));
        jPanel7.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        sinNovedadesBTN.setBackground(new java.awt.Color(205, 200, 177));
        sinNovedadesBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/blanquear.gif"))); // NOI18N
        sinNovedadesBTN.setText("  Sin novedades");
        sinNovedadesBTN.setEnabled(false);
        sinNovedadesBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sinNovedadesBTNActionPerformed(evt);
            }
        });
        sinNovedadesBTN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                sinNovedadesBTNKeyReleased(evt);
            }
        });
        jPanel7.add(sinNovedadesBTN, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, -1, -1));

        jLabel25.setText("Cant. horas:");
        jPanel7.add(jLabel25, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 0, -1, -1));

        jLabel27.setText("Nro. de hoja:");
        jPanel7.add(jLabel27, new org.netbeans.lib.awtextra.AbsoluteConstraints(466, 4, -1, -1));

        jTextField28.setText("1");
        jTextField28.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField28.setEnabled(false);
        jTextField28.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField28FocusLost(evt);
            }
        });
        jTextField28.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField28KeyReleased(evt);
            }
        });
        jPanel7.add(jTextField28, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 1, 29, -1));

        jTextField29.setText("0");
        jTextField29.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.black, java.awt.Color.white));
        jTextField29.setEnabled(false);
        jTextField29.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField29KeyReleased(evt);
            }
        });
        jPanel7.add(jTextField29, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 0, 35, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 737, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 727, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 727, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 727, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 712, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 727, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //Habilita menu movimientos si no hay otra ventana abierta.
    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        abierta = false;
    }//GEN-LAST:event_formInternalFrameClosed

    //Metodo para cerra la ventana interna
    private void salirBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirBTNActionPerformed
        this.dispose();
    }//GEN-LAST:event_salirBTNActionPerformed

    //Pone los TF del modulo 1 en blanco.
    private void inicializarControles(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                textField.setText("");
            }
        }
    }
    
    //El botón limpiar, limpia el primer modulo.
    private void limpiarBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiarBTNActionPerformed
        inicializarControles(jPanel1);
        jComboBox1.setSelectedIndex(0);
        jComboBox2.setSelectedIndex(0);
        jTextField1.requestFocus();
        jLabel7.setText("0");
        jComboBox3.setSelectedIndex(0);
    }//GEN-LAST:event_limpiarBTNActionPerformed

    //selecciona item en el combo Departamento deacuerdo al contenido del Textfiel,
    //valida que el codigo ingresado se encuentre en la tabla Departamento y paso de foco
    @SuppressWarnings("empty-statement")
    private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            
            String campo = "select * from siesca.departamento";           

            try {
                Connection conn = AdministradorDeConexiones.obtenerConexion();
                Statement st = conn.createStatement();
                ResultSet rs = st.executeQuery(campo);

                boolean bandera = false;
                while (rs.next()) {
                    int id = rs.getInt("id");
                    String descripcion = rs.getString("descripcion");

                    if (id == Integer.parseInt(jTextField1.getText())) {
                        bandera = true;
                        jComboBox1.setSelectedItem(descripcion);
                        jTextField2.requestFocus();
                        jTextField2.selectAll();
                    }
                }

                if (bandera == false) {
                    jLabel1.requestFocus();
                    JOptionPane.showMessageDialog(this, "Codigo incorrecto", "Advertencia", 0,
                            new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                }
                rs.close();
                st.close();
                conn.close();
            // Este catch es para evitar el jTextfield en blanco.    
            } catch (NumberFormatException ex) {
                jLabel1.requestFocus();
                JOptionPane.showMessageDialog(this, "Código incorrecto", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            } catch (Exception er) {
                jLabel1.requestFocus();
                JOptionPane.showMessageDialog(this, "No hay conexión con la base de datos", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            }
        }
    }//GEN-LAST:event_jTextField1KeyReleased

    //selecciona item en el combo Establecimiento deacuerdo al contenido del Textfiel,
    // valida que el codigo ingresado se encuentre el la tabla Establecimiento y paso de foco
    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {

            if ("".equals(jTextField1.getText())) {
                JOptionPane.showMessageDialog(this, "Debe indicar el código de Departamento", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                jLabel1.requestFocus();
            } else {
                String campo = "select * from siesca.establecimiento";

                try {
                    Connection conn = AdministradorDeConexiones.obtenerConexion();
                    Statement st = conn.createStatement();
                    ResultSet rs = st.executeQuery(campo);

                    boolean bandera = false;

                    while (rs.next()) {
                        int id_departamento = rs.getInt("id_departamento");
                        int id = rs.getInt("id");
                        String descripcion = rs.getString("descripcion");
                        String area = rs.getString("area");

                        if (id_departamento == Integer.parseInt(jTextField1.getText()) && id == Integer.parseInt(jTextField2.getText())) {
                            bandera = true;
                            jLabel7.setText(area);
                            jComboBox2.setSelectedItem(descripcion);
                            jTextField3.requestFocus();
                            jTextField3.selectAll();
                        }
                    }

                    if (bandera == false) {
                        jTextField1.requestFocus();
                        jTextField1.selectAll();
                        JOptionPane.showMessageDialog(this, "Codigo incorrecto", "Advertencia", 0,
                                new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                    }

                    rs.close();
                    st.close();
                    conn.close();

                } catch (NumberFormatException ex) {
                    jTextField1.requestFocus();
                    jTextField1.selectAll();
                    JOptionPane.showMessageDialog(this, "Código incorrecto", "Advertencia", 0,
                            new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                } catch (Exception er) {
                    JOptionPane.showMessageDialog(this, "No hay conexión con la base de datos", "Advertencia", 0,
                            new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                }
            }
        }
        
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            jTextField1.requestFocus();
            jTextField1.selectAll();
        }
    }//GEN-LAST:event_jTextField2KeyReleased

    //selecciona item en el combo Servicio deacuerdo al contenido del Textfiel,
    // valida que el codigo ingresado se encuentre el la tabla Servicio y paso de foco
    private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {

            String campo = "select * from siesca.servicio";

            try {
                Connection conn = AdministradorDeConexiones.obtenerConexion();
                Statement st = conn.createStatement();
                ResultSet rs = st.executeQuery(campo);

                boolean bandera = false;

                while (rs.next()) {
                    int id = rs.getInt("id");
                    String descripcion = rs.getString("descripcion");

                    if (id == Integer.parseInt(jTextField3.getText())) {
                        bandera = true;
                        jComboBox3.setSelectedItem(descripcion);
                        jTextField4.requestFocus();
                        jTextField4.selectAll();
                    }
                }

                if (bandera == false) {
                    jTextField2.requestFocus();
                    JOptionPane.showMessageDialog(this, "Codigo incorrecto", "Advertencia", 0,
                            new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                }

                rs.close();
                st.close();
                conn.close();
            } catch (NumberFormatException ex) {
                jTextField2.requestFocus();
                JOptionPane.showMessageDialog(this, "Código incorrecto", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            } catch (Exception er) {
                JOptionPane.showMessageDialog(this, "No hay conexión con la base de datos", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            }
        }

        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            jTextField2.requestFocus();
            jTextField2.selectAll();
        }
    }//GEN-LAST:event_jTextField3KeyReleased

    //Paso de foco.
    private void jTextField4KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyReleased
        pasarFocoTF(jTextField3, jTextField5, evt);
    }//GEN-LAST:event_jTextField4KeyReleased

    
    //Valida que los Textfield del primer modulo no esten en blanco 
    //y el mes no sea superior a 12
    private void validarTF1M() {
        boolean bandera= true;
        String nombreTF = "";
        if (jTextField1.getText().length() < 1) {
            nombreTF = "DEPARTAMENTO";
            jLabel1.requestFocus();
        } else if (jTextField2.getText().length() < 1) {
            nombreTF = "ESTABLECIMIENTO";
            jTextField1.requestFocus();
        } else if (jTextField3.getText().length() < 1) {
            nombreTF = "SERVICIO";
            jTextField2.requestFocus();
        } else if (jTextField4.getText().length() < 1) {
            nombreTF = "ORDEN";
            jTextField3.requestFocus();
        } else if (jTextField5.getText().length() < 1) {
            nombreTF = "MES";
            jTextField4.requestFocus();
            //validar mes
        } else if (Integer.parseInt(jTextField5.getText()) > 12 || Integer.parseInt(jTextField5.getText()) < 1){
                JOptionPane.showMessageDialog(this,
                        "El mes ingresado es incorrecto",
                        "Error", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/errorDI.png")));
                bandera=false;
                jTextField4.requestFocus();
            } else {
            
            String campo = "select * from `siesca`.`datos"+jLabel29.getText()+"`";
            
            try {
                Connection conn = AdministradorDeConexiones.obtenerConexion();
                Statement st = conn.createStatement();
                ResultSet rs = st.executeQuery(campo);

                while (rs.next()) {
                    int id_departamento = rs.getInt("id_departamento");
                    int id_establecimiento = rs.getInt("id_establecimiento");
                    int id_servicio = rs.getInt("id_servicio");
                    int orden = rs.getInt("orden");
                    int mes = rs.getInt("mes");
                    
                    if ((id_departamento == Integer.parseInt(jTextField1.getText())) && (id_establecimiento == Integer.parseInt(jTextField2.getText())) && (id_servicio == Integer.parseInt(jTextField3.getText())) && (orden == Integer.parseInt(jTextField4.getText())) && (mes == Integer.parseInt(jTextField5.getText()))) {
                        JOptionPane.showMessageDialog(this, "El registro ya existe", "Advertencia", 0,
                                new javax.swing.ImageIcon(getClass().getResource("/imagenes/informacion.png")));
                        bandera=false;
                        jLabel1.requestFocus();
                    }                     
                }                      
                rs.close();
                st.close();
                conn.close();
            } catch (Exception er) {
                jLabel1.requestFocus();
                JOptionPane.showMessageDialog(this, "Debe seleccionar el año", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            }               
            }

        if (nombreTF.length() > 0) {
            JOptionPane.showMessageDialog(this, "El campo " + nombreTF
                    + " no puede estar vacio", "Advertencia", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                   bandera=false;
        }
        
        if(bandera){                            
                        bloquearControles1Modulo(jPanel1);
                        habilitarSegundoModulo();
                        sinNovedadesBTN.requestFocus();
        }
    }
    
    //Metodo para evitar campos nulos
    private void evitarCampoNulo(JTextField elTF) {
        if (elTF.getText().length() < 1) {
            elTF.setText("0");
            elTF.selectAll();
        }
    }
    
    //Evita campos nulos en pacientes y suma consultas
    private void validarTFPacientes() {
        evitarCampoNulo(jTextField8);
        evitarCampoNulo(jTextField9);
        int sum1 = Integer.parseInt(jTextField8.getText()) + Integer.parseInt(jTextField9.getText());
        jLabel44.setText("" + sum1);
        jLabel44.setForeground(Color.BLUE);
        int dif1 = sum1 - Integer.parseInt(jLabel14.getText());
        jLabel57.setText("" + dif1);
        jLabel57.setForeground(Color.RED);
    }

    //Evita campos nulos en sexo y edad y suma consultas
    private int sumaConsEdadSexo(JPanel panel) {
        int sum = 0;
        for (int i = 0; i < panel.getComponentCount(); i++) {
            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                evitarCampoNulo(textField);
            }

            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                sum += Integer.parseInt(textField.getText());
            }
        }
        return sum;
    }
        
    //Calcula totales en cosultas y los muestra en etiqutas.
    private void validarTFSexoEdad() {
        sumaConsEdadSexo(jPanel2);
        int suma= sumaConsEdadSexo(jPanel2);
        jLabel14.setText("" + suma);
        jLabel14.setForeground(Color.BLUE);
        int dif1 = Integer.parseInt(jLabel44.getText())
                - Integer.parseInt(jLabel14.getText());
        jLabel57.setText("" + dif1);
        jLabel57.setForeground(Color.RED);
        int dif2 = Integer.parseInt(jLabel14.getText())
                - Integer.parseInt(jLabel10.getText());
        jLabel50.setText("" + dif2);
        jLabel50.setForeground(Color.RED);
    }

    //Evita campos nulos en diagnostico y suma consultas
    private void validarTFDiagnostico() {
        evitarCampoNulo(jTextField10);
        evitarCampoNulo(jTextField25);
        int sum1 = Integer.parseInt(jTextField10.getText()) + Integer.parseInt(jTextField25.getText());
        jLabel10.setText("" + sum1);
        jLabel10.setForeground(Color.BLUE);
        int dif3 = Integer.parseInt(jLabel14.getText()) - Integer.parseInt(jLabel10.getText());
        jLabel50.setText("" + dif3);
        jLabel50.setForeground(Color.RED);
    }

    //Validacion capos clave y paso de foco
    private void jTextField5KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            validarTF1M();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            jTextField4.requestFocus();
            jTextField4.selectAll();
        }
    }//GEN-LAST:event_jTextField5KeyReleased

    //el boton guardar cuando suelta una tecla.
    private void guardarBTNKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_guardarBTNKeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            
            try {                
                Connection conn = AdministradorDeConexiones.obtenerConexion();
                PreparedStatement preparedStatement = conn.prepareStatement("INSERT INTO `siesca`.`datos"+jLabel29.getText()+"`"
            +"(`anio`, `provincia`, `id_departamento`, `id_establecimiento`,"
            +"`id_servicio`, `orden`, `mes`, `id_area`, `horas`, `hoja`, "
            +"`C_nuevas`, `C_repetidas`, `C_mas_men_1`, `C_fem_men_1`, "
            +"`C_mas_1`, `C_fem_1`, `C_mas_2a4`, `C_fem_2a4`, `C_mas_5a9`, "
            +"`C_fem_5a9`, `C_mas_10a14`, `C_fem_10a14`, `C_mas_15a49`, "
            +"`C_fem_15a49`, `C_mas_may_50`, `C_fem_may_50`, `C_1_vez`, "
            +"`C_ult_vez`, `C_total`, `T_control_embarazo`)VALUES ('"+jLabel29.getText()+"', '10', '"+Integer.parseInt (jTextField1.getText())+"', '"+Integer.parseInt (jTextField2.getText())+"', "
            +"'"+Integer.parseInt (jTextField3.getText())+"', '"+Integer.parseInt (jTextField4.getText())+"', '"+Integer.parseInt (jTextField5.getText())+"',"
            +"'"+Integer.parseInt (jLabel7.getText())+"', '"+Integer.parseInt (jTextField29.getText())+"', '"+Integer.parseInt (jTextField28.getText())+"', "
            +"'"+Integer.parseInt (jTextField8.getText())+"', '"+Integer.parseInt (jTextField9.getText())+"', '"+Integer.parseInt (jTextField11.getText())+"', "
            +"'"+Integer.parseInt (jTextField12.getText())+"', '"+Integer.parseInt (jTextField13.getText())+"', '"+Integer.parseInt (jTextField14.getText())+"', "
            +"'"+Integer.parseInt (jTextField15.getText())+"', '"+Integer.parseInt (jTextField16.getText())+"', '"+Integer.parseInt (jTextField17.getText())+"', "
            +"'"+Integer.parseInt (jTextField18.getText())+"', '"+Integer.parseInt (jTextField19.getText())+"', '"+Integer.parseInt (jTextField20.getText())+"', "
            +"'"+Integer.parseInt (jTextField21.getText())+"', '"+Integer.parseInt (jTextField22.getText())+"', '"+Integer.parseInt (jTextField23.getText())+"', "
            +"'"+Integer.parseInt (jTextField24.getText())+"', '"+Integer.parseInt (jTextField10.getText())+"', '"+Integer.parseInt (jTextField25.getText())+"', "
            +"'"+Integer.parseInt (jLabel44.getText())+"', '"+Integer.parseInt (jTextField26.getText())+"')");
                preparedStatement.executeUpdate();

                jLabel1.requestFocus();
                JOptionPane.showMessageDialog(this,
                        "El registro se ha guardado",
                        "Aviso", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/informacion.png")));;

                limpiarControles2Modulo(jPanel2);
                limpiarControles2Modulo(jPanel3);
                limpiarControles2Modulo(jPanel4);
                limpiarControles2Modulo(jPanel5);
                limpiarControles2Modulo(jPanel7);
                jLabel44.setText("0");
                jLabel14.setText("0");
                jLabel10.setText("0");
                jLabel50.setText("0");
                jLabel57.setText("0");
                BloquearSegundoModulo();
                habilitarPanel(jPanel1);
                jComboBox1.setEnabled(false);
                jComboBox2.setEnabled(false);

                preparedStatement.close();
                conn.close();


            } catch (SQLException es) {
                JOptionPane.showMessageDialog(this,
                        "Debe seleccionar el año de ingreso",
                        "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                this.dispose();

            } catch (Exception er) {
                JOptionPane.showMessageDialog(this,
                        "No se pudo guardar el registro",
                        "Error", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/errorDI.png")));
            }
        }

        
        if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
            salirBTN.requestFocus();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            habilitarSegundoModulo();
            jTextField26.requestFocus();
            jTextField26.selectAll();
            guardarBTN.setEnabled(false);
        }
    }//GEN-LAST:event_guardarBTNKeyReleased

    //boton salir.
    private void salirBTNKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_salirBTNKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.dispose();
        }
        if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
            guardarBTN.requestFocus();
        }
    }//GEN-LAST:event_salirBTNKeyReleased

    //paso de foco.
    private void jTextField29KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField29KeyReleased
        evitarCampoNulo(jTextField29);
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jTextField28.requestFocus();
            jTextField28.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            evitarCampoNulo(jTextField29);
            sinNovedadesBTN.requestFocus();
        }
    }//GEN-LAST:event_jTextField29KeyReleased

    private void limpiarControles2Modulo(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            if (panel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) panel.getComponent(i);
                textField.setText("0");
            }
        }
    }
        
    //Botón sin novedades, pone ceros.
    private void sinNovedadesBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sinNovedadesBTNActionPerformed

        limpiarControles2Modulo(jPanel2);
        limpiarControles2Modulo(jPanel3);
        limpiarControles2Modulo(jPanel4);
        limpiarControles2Modulo(jPanel5);
        limpiarControles2Modulo(jPanel7);
        BloquearSegundoModulo();
        jLabel44.setText("0");
        jLabel14.setText("0");
        jLabel10.setText("0");
        jLabel50.setText("0");
        jLabel57.setText("0");
        jTextField28.setText("1");
        guardarBTN.setEnabled(true);
        guardarBTN.requestFocus();

    }//GEN-LAST:event_sinNovedadesBTNActionPerformed

    //Boton sin novedades Enter y Up
    private void sinNovedadesBTNKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sinNovedadesBTNKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jTextField29.requestFocus();
            jTextField29.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            BloquearSegundoModulo();
            habilitarPanel(jPanel1);
            jComboBox1.setEnabled(false);
            jComboBox2.setEnabled(false);
            jTextField5.requestFocus();
            jTextField5.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_ADD) {
            limpiarControles2Modulo(jPanel2);
            limpiarControles2Modulo(jPanel3);
            limpiarControles2Modulo(jPanel4);
            limpiarControles2Modulo(jPanel5);
            limpiarControles2Modulo(jPanel7);
            BloquearSegundoModulo();
            jLabel44.setText("0");
            jLabel14.setText("0");
            jLabel10.setText("0");
            jLabel50.setText("0");
            jLabel57.setText("0");
            jTextField28.setText("1");
            guardarBTN.setEnabled(true);
            guardarBTN.requestFocus();
        }
    }//GEN-LAST:event_sinNovedadesBTNKeyReleased

    //Evitar nulo y pasar foco.
    private void jTextField28KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField28KeyReleased
        evitarCampoNulo(jTextField28);
        pasarFocoTF(jTextField29, jTextField8, evt);
    }//GEN-LAST:event_jTextField28KeyReleased

    private void jTextField9KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField9KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ADD) {
            jTextField26.requestFocus();
            jTextField26.selectAll();
        }
        validarTFPacientes();
        pasarFocoTF(jTextField8, jTextField11, evt);

    }//GEN-LAST:event_jTextField9KeyReleased

    private void jTextField8KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField8KeyReleased
        validarTFPacientes();
        pasarFocoTF(jTextField28, jTextField9, evt);
    }//GEN-LAST:event_jTextField8KeyReleased

    private void jTextField11KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField11KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField9, jTextField12, evt);
        if (evt.getKeyCode() == KeyEvent.VK_ADD) {
            jTextField21.requestFocus();
            jTextField21.selectAll();
        }
    }//GEN-LAST:event_jTextField11KeyReleased

    private void jTextField12KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField12KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField11, jTextField13, evt);
    }//GEN-LAST:event_jTextField12KeyReleased

    private void jTextField13KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField13KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField12, jTextField14, evt);
    }//GEN-LAST:event_jTextField13KeyReleased

    private void jTextField15KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField15KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField14, jTextField16, evt);
    }//GEN-LAST:event_jTextField15KeyReleased

    private void jTextField16KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField16KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField15, jTextField17, evt);
    }//GEN-LAST:event_jTextField16KeyReleased

    private void jTextField17KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField17KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField16, jTextField18, evt);
    }//GEN-LAST:event_jTextField17KeyReleased

    private void jTextField18KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField18KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField17, jTextField19, evt);
    }//GEN-LAST:event_jTextField18KeyReleased

    private void jTextField19KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField19KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField18, jTextField20, evt);
    }//GEN-LAST:event_jTextField19KeyReleased

    private void jTextField20KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField20KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField19, jTextField21, evt);
    }//GEN-LAST:event_jTextField20KeyReleased

    private void jTextField21KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField21KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField20, jTextField22, evt);
    }//GEN-LAST:event_jTextField21KeyReleased

    private void jTextField22KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField22KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField21, jTextField23, evt);
    }//GEN-LAST:event_jTextField22KeyReleased

    private void jTextField23KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField23KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField22, jTextField24, evt);
    }//GEN-LAST:event_jTextField23KeyReleased

    private void jTextField24KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField24KeyReleased
        validarTFSexoEdad();
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jTextField10.requestFocus();
            jTextField10.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            jTextField23.requestFocus();
            jTextField23.selectAll();
        }
    }//GEN-LAST:event_jTextField24KeyReleased

    private void jTextField10KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField10KeyReleased
        validarTFDiagnostico();
        pasarFocoTF(jTextField24, jTextField25, evt);
    }//GEN-LAST:event_jTextField10KeyReleased

    private void jTextField25KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField25KeyReleased
        validarTFDiagnostico();
        pasarFocoTF(jTextField10, jTextField26, evt);
    }//GEN-LAST:event_jTextField25KeyReleased

    private void jTextField26KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField26KeyReleased
        evitarCampoNulo(jTextField26);
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if (jLabel44.getText().equals(jLabel14.getText())
                    && jLabel14.getText().equals(jLabel10.getText())&& (Integer.parseInt (jTextField26.getText())<= Integer.parseInt (jLabel10.getText()) )) {
                BloquearSegundoModulo();
                guardarBTN.setEnabled(true);
                guardarBTN.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "Los totales de las consultas deben ser iguales y el control de embarazo menor o igual al de consultas", "Advertencia", 0,
                        new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
                jTextField28.requestFocus();
            }
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            jTextField25.requestFocus();
            jTextField25.selectAll();
        }
    }//GEN-LAST:event_jTextField26KeyReleased

    private void jTextField14KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField14KeyReleased
        validarTFSexoEdad();
        pasarFocoTF(jTextField13, jTextField15, evt);
    }//GEN-LAST:event_jTextField14KeyReleased

    private void jLabel1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jLabel1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jTextField1.requestFocus();
            jTextField1.selectAll();
        }
    }//GEN-LAST:event_jLabel1KeyReleased

    private void jTextField28FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField28FocusLost
        if ("0".equals(jTextField28.getText())) {
            jTextField28.setText("1");
        }
    }//GEN-LAST:event_jTextField28FocusLost

    private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField4FocusLost
        if ("".equals(jTextField4.getText()) || "0".equals(jTextField4.getText())) {
            jTextField4.setText("1");
        }
    }//GEN-LAST:event_jTextField4FocusLost

    //Metodos para asignar el codigo de servicio al TF desde el CMB
    private void jComboBox3ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox3ItemStateChanged
        String sql="Select * from SiEsCA.servicio where descripcion = '"+jComboBox3.getSelectedItem()+"';";
    try{

        Connection conn = AdministradorDeConexiones.obtenerConexion();
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(sql);
        while (rs.next()) 
        {
        String id =rs.getString("id").toString();   
        jTextField3.setText(id);
        jTextField4.requestFocus();
        }
    st.close();
    conn.close();
    }
    catch (Exception er){
    JOptionPane.showMessageDialog(this, "No hay conexión con la base de datos", "Advertencia", 0,
                                new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
    }
    }//GEN-LAST:event_jComboBox3ItemStateChanged

    private void jComboBox2InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jComboBox2InputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2InputMethodTextChanged

    private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField2MouseClicked
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField2MouseClicked

    private void jTextField3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField3MouseClicked
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField3MouseClicked

    private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField4MouseClicked
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField4MouseClicked

    private void jTextField5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField5MouseClicked
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField5MouseClicked

    private void jTextField2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField2MousePressed
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField2MousePressed

    private void jTextField3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField3MousePressed
       jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField3MousePressed

    private void jTextField4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField4MousePressed
       jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField4MousePressed

    private void jTextField5MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField5MousePressed
        jTextField1.requestFocus();
    }//GEN-LAST:event_jTextField5MousePressed

    // hace lo mismo que el enter en el boton guardar.
    private void guardarBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarBTNActionPerformed
                    try {
                
                Connection conn = AdministradorDeConexiones.obtenerConexion();
                PreparedStatement preparedStatement = conn.prepareStatement("INSERT INTO `siesca`.`datos"+jLabel29.getText()+"`"
            +"(`anio`, `provincia`, `id_departamento`, `id_establecimiento`,"
            +"`id_servicio`, `orden`, `mes`, `id_area`, `horas`, `hoja`, "
            +"`C_nuevas`, `C_repetidas`, `C_mas_men_1`, `C_fem_men_1`, "
            +"`C_mas_1`, `C_fem_1`, `C_mas_2a4`, `C_fem_2a4`, `C_mas_5a9`, "
            +"`C_fem_5a9`, `C_mas_10a14`, `C_fem_10a14`, `C_mas_15a49`, "
            +"`C_fem_15a49`, `C_mas_may_50`, `C_fem_may_50`, `C_1_vez`, "
            +"`C_ult_vez`, `C_total`, `T_control_embarazo`)VALUES ('"+jLabel29.getText()+"', '10', '"+Integer.parseInt (jTextField1.getText())+"', '"+Integer.parseInt (jTextField2.getText())+"', "
            +"'"+Integer.parseInt (jTextField3.getText())+"', '"+Integer.parseInt (jTextField4.getText())+"', '"+Integer.parseInt (jTextField5.getText())+"',"
            +"'"+Integer.parseInt (jLabel7.getText())+"', '"+Integer.parseInt (jTextField29.getText())+"', '"+Integer.parseInt (jTextField28.getText())+"', "
            +"'"+Integer.parseInt (jTextField8.getText())+"', '"+Integer.parseInt (jTextField9.getText())+"', '"+Integer.parseInt (jTextField11.getText())+"', "
            +"'"+Integer.parseInt (jTextField12.getText())+"', '"+Integer.parseInt (jTextField13.getText())+"', '"+Integer.parseInt (jTextField14.getText())+"', "
            +"'"+Integer.parseInt (jTextField15.getText())+"', '"+Integer.parseInt (jTextField16.getText())+"', '"+Integer.parseInt (jTextField17.getText())+"', "
            +"'"+Integer.parseInt (jTextField18.getText())+"', '"+Integer.parseInt (jTextField19.getText())+"', '"+Integer.parseInt (jTextField20.getText())+"', "
            +"'"+Integer.parseInt (jTextField21.getText())+"', '"+Integer.parseInt (jTextField22.getText())+"', '"+Integer.parseInt (jTextField23.getText())+"', "
            +"'"+Integer.parseInt (jTextField24.getText())+"', '"+Integer.parseInt (jTextField10.getText())+"', '"+Integer.parseInt (jTextField25.getText())+"', "
            +"'"+Integer.parseInt (jLabel44.getText())+"', '"+Integer.parseInt (jTextField26.getText())+"')");
                preparedStatement.executeUpdate();

                        jLabel1.requestFocus();

                        JOptionPane.showMessageDialog(this,
                                "El registro se ha guardado",
                                "Aviso", 0,
                                new javax.swing.ImageIcon(getClass().getResource("/imagenes/informacion.png")));;

                        limpiarControles2Modulo(jPanel2);
                        limpiarControles2Modulo(jPanel3);
                        limpiarControles2Modulo(jPanel4);
                        limpiarControles2Modulo(jPanel5);
                        limpiarControles2Modulo(jPanel7);
                        jLabel44.setText("0");
                        jLabel14.setText("0");
                        jLabel10.setText("0");
                        jLabel50.setText("0");
                        jLabel57.setText("0");
                        BloquearSegundoModulo();
                        habilitarPanel(jPanel1);
                        jComboBox1.setEnabled(false);
                        jComboBox2.setEnabled(false);

                        preparedStatement.close();
                        conn.close();


        } catch (SQLException es) {
            JOptionPane.showMessageDialog(this,
                    "Debe seleccionar el año de ingreso",
                    "Advertencia", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/advertenciaDI.png")));
            this.dispose();

        } catch (Exception er) {
            JOptionPane.showMessageDialog(this,
                    "No se pudo guardar el registro",
                    "Error", 0,
                    new javax.swing.ImageIcon(getClass().getResource("/imagenes/errorDI.png")));
        }
    }//GEN-LAST:event_guardarBTNActionPerformed

    private void jTextField9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField9MouseClicked
        jTextField9.selectAll();
    }//GEN-LAST:event_jTextField9MouseClicked

    private void jTextField26MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField26MouseClicked
        jTextField26.selectAll();
    }//GEN-LAST:event_jTextField26MouseClicked

    private void jTextField9MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField9MouseReleased
        jTextField9.selectAll();
    }//GEN-LAST:event_jTextField9MouseReleased

    private void jTextField26MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField26MouseReleased
        jTextField26.selectAll();
    }//GEN-LAST:event_jTextField26MouseReleased

    //Metodo pasar foco
    private void pasarFocoTF(JTextField textFieldAnterior,
            JTextField textFielPosterior, java.awt.event.KeyEvent evt) {

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            textFielPosterior.requestFocus();
            textFielPosterior.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            textFieldAnterior.requestFocus();
            textFieldAnterior.selectAll();
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton guardarBTN;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField14;
    private javax.swing.JTextField jTextField15;
    private javax.swing.JTextField jTextField16;
    private javax.swing.JTextField jTextField17;
    private javax.swing.JTextField jTextField18;
    private javax.swing.JTextField jTextField19;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField20;
    private javax.swing.JTextField jTextField21;
    private javax.swing.JTextField jTextField22;
    private javax.swing.JTextField jTextField23;
    private javax.swing.JTextField jTextField24;
    private javax.swing.JTextField jTextField25;
    private javax.swing.JTextField jTextField26;
    private javax.swing.JTextField jTextField27;
    private javax.swing.JTextField jTextField28;
    private javax.swing.JTextField jTextField29;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JButton limpiarBTN;
    private javax.swing.JButton salirBTN;
    private javax.swing.JButton sinNovedadesBTN;
    // End of variables declaration//GEN-END:variables
}
